package com.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.jee.support.dao.ITestDBDAO;
import com.jee.support.pojo.TestDB;

public class ITestTestDBDAO {
	
	public static void main(String[] args) {
		long t1 = System.currentTimeMillis();
		ExecutorService exec = Executors.newCachedThreadPool();
		for (int i = 0; i < 20; i++) {
			exec.execute(new DbRunner());
		}
		exec.shutdown();
		System.out.println(System.currentTimeMillis() - t1);
	}
}

class DbRunner implements Runnable{

	@Override
	public void run() {
		String str = "abcdefghijklmnopqrstuvwxyz";
		ApplicationContext applicationContext = new FileSystemXmlApplicationContext("src/main/resource/jee.application.xml");		
		ITestDBDAO testDBDAO = (ITestDBDAO)applicationContext.getBean("testDBDAO");
		
		for(int i = 0;i < 50000;i++){
			char a = str.charAt(i%26);
			StringBuffer buffer = new StringBuffer(a);
			TestDB testDB = new TestDB();
			testDB.setName(buffer.toString());
			testDBDAO.insertTestDB(testDB);
		}
	}
	
}